home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
dev
/
lang
/
fpcsrc.lha
/
fpc
/
compiler
/
ag386int.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1998-09-24
|
31KB
|
797 lines
{
$Id: ag386int.pas,v 1.1.1.1.2.2 1998/05/25 23:00:22 carl Exp $
Copyright (c) 1996,97 by Florian Klaempfl
This unit implements an asmoutput class for Intel syntax with Intel i386+
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
****************************************************************************
}
{$R-}
unit ag386int;
interface
uses aasm,assemble;
type
pi386intasmlist=^ti386intasmlist;
ti386intasmlist = object(tasmlist)
procedure WriteTree(p:paasmoutput);virtual;
procedure WriteAsmList;virtual;
end;
implementation
uses
dos,globals,systems,cobjects,i386,
strings,files,verbose
{$ifdef GDB}
,gdb
{$endif GDB}
;
const
line_length = 70;
extstr : array[EXT_NEAR..EXT_ABS] of String[8] =
('NEAR','FAR','PROC','BYTE','WORD','DWORD',
'CODEPTR','DATAPTR','FWORD','PWORD','QWORD','TBYTE','ABS');
function getreferencestring(const ref : treference) : string;
var
s : string;
first : boolean;
begin
if ref.isintvalue then
s:= tostr(ref.offset)
else
{$ifdef ver0_6}
begin
first:=true;
{ have we a segment prefix ? }
if ref.segment<>R_DEFAULT_SEG then
begin
if current_module^.output_format in [of_nasm,of_obj] then
s:='['+_reg2str[ref.segment]+':'
else
s:=_reg2str[ref.segment]+':[';
end
else s:='[';
if assigned(ref.symbol) then
begin
s:=s+ref.symbol^;
first:=false;
end;
if (ref.base<>R_NO) then
begin
if not(first) then
s:=s+'+'
else
first:=false;
s:=s+_reg2str[ref.base];
end;
if (ref.index<>R_NO) then
begin
if not(first) then
s:=s+'+'
else
first:=false;
s:=s+_reg2str[ref.index];
if ref.scalefactor<>0 then
s:=s+'*'+tostr(ref.scalefactor);
end;
if ref.offset<0 then
s:=s+tostr(ref.offset)
else if (ref.offset>0) then
s:=s+'+'+tostr(ref.offset);
s:=s+']';
end;
{$else}
with ref do
begin
first:=true;
if ref.segment<>R_DEFAULT_SEG then
begin
if current_module^.output_format in [of_nasm,of_obj] then
s:='['+int_reg2str[segment]+':'
else
s:=int_reg2str[segment]+':[';
end
else
s:='[';
if assigned(symbol) then
begin
s:=s+symbol^;
first:=false;
end;
if (base<>R_NO) then
begin
if not(first) then
s:=s+'+'
else
first:=false;
s:=s+int_reg2str[base];
end;
if (index<>R_NO) then
begin
if not(first) then
s:=s+'+'
else
first:=false;
s:=s+int_reg2str[index];
if scalefactor<>0 then
s:=s+'*'+tostr(scalefactor);
end;
if offset<0 then
s:=s+tostr(offset)
else if (offset>0) then
s:=s+'+'+tostr(offset);
s:=s+']';
end;
{$endif}
getreferencestring:=s;
end;
function getopstr(t : byte;o : pointer;s : topsize; _operator: tasmop;dest : boolean) : string;
var
hs : string;
begin
case t of
top_reg : { a floating point register can be only a register operand }
if current_module^.output_format in [of_nasm,of_obj] then
getopstr:=int_nasmreg2str[tregister(o)]
else
getopstr:=int_reg2str[tregister(o)];
top_const,
top_ref : begin
if t=top_const then
hs := tostr(longint(o))
else
hs:=getreferencestring(preference(o)^);
if current_module^.output_format in [of_nasm,of_obj] then
if (_operator = A_LEA) or (_operator = A_LGS)
or (_operator = A_LSS) or (_operator = A_LFS)
or (_operator = A_LES) or (_operator = A_LDS)
or (_operator = A_SHR) or (_operator = A_SHL)
or (_operator = A_SAR) or (_operator = A_SAL)
or (_operator = A_OUT) or (_operator = A_IN) then
begin
end
else
case s of
S_B : hs:='byte '+hs;
S_W : hs:='word '+hs;
S_L : hs:='dword '+hs;
S_S : hs:='dword '+hs;
S_Q : hs:='qword '+hs;
S_X : if current_module^.output_format in [of_nasm,of_obj] then
hs:='tword '+hs
else
hs:='tbyte '+hs;
S_BW : if dest then
hs:='word '+hs
else
hs:='byte '+hs;
S_BL : if dest then
hs:='dword '+hs
else
hs:='byte '+hs;
S_WL : if dest then
hs:='dword '+hs
else
hs:='word '+hs;
end
else
Begin
{ can possibly give a range check error under tp }
{ if using in... }
if ((_operator <> A_LGS) and (_operator <> A_LSS) and
(_operator <> A_LFS) and (_operator <> A_LDS) and
(_operator <> A_LES)) then
Begin
case s of
S_B : hs:='byte ptr '+hs;
S_W : hs:='word ptr '+hs;
S_L : hs:='dword ptr '+hs;
S_BW : if dest then
hs:='word ptr '+hs
else
hs:='byte ptr '+hs;
S_BL : if dest then
hs:='dword ptr '+hs
else
hs:='byte ptr '+hs;
S_WL : if dest then
hs:='dword ptr '+hs
else
hs:='word ptr '+hs;
end;
end;
end;
getopstr:=hs;
end;
top_symbol : begin
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));
move(pchar(pcsymbol(o)^.symbol)^,hs[1],byte(hs[0]));
if current_module^.output_format=of_masm then
hs:='offset '+hs
else
hs:='dword '+hs;
if pcsymbol(o)^.offset>0 then
hs:=hs+'+'+tostr(pcsymbol(o)^.offset)
else if pcsymbol(o)^.offset<0 then
hs:=hs+tostr(pcsymbol(o)^.offset);
getopstr:=hs;
end;
else internalerror(10001);
end;
end;
function getopstr_jmp(t : byte;o : pointer) : string;
var
hs : string;
begin
case t of
top_reg : getopstr_jmp:=int_reg2str[tregister(o)];
top_ref : getopstr_jmp:=getreferencestring(preference(o)^);
top_const : getopstr_jmp:=tostr(longint(o));
top_symbol : begin
hs[0]:=chr(strlen(pchar(pcsymbol(o)^.symbol)));